package zero.tech.games.gate.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import zero.tech.games.entity.games.ClubMember;

public interface ClubMemberMapper {

	@Select("select * from club_member where club_id=#{club_id} and uid=#{uid}")
	ClubMember selectClubMemberByClubIdAndUid(int club_id,int uid);
	@Insert("insert into club_member(club_id,uid,tea,safety,frozen) value(#{club_id},#{uid},#{tea},#{safety},#{frozen})")
	void insert(ClubMember clubMember);
	
	@Select("select ifnull(sum(t1.tea+t1.safety),0) from club_member t1 left join club_member_proxy t2 "
			+ "on t1.club_id=t2.club_id and t1.uid=t2.uid where t1.club_id=#{club_id} and t2.father_uid=#{uid}")
	long selectClubZsMemberTotalTea(int club_id,int uid);
	
	long selectClubHehuorenMemberTotalTea(@Param("club_id")int club_id, @Param("list")List<Integer> list);
	
	@Update("update club_member set tea=tea-#{tea} where club_id=#{club_id} and uid=#{uid}")
	void reduceTea(int club_id,int uid, long tea);
	
	@Update("update club_member set tea=tea+#{tea} where club_id=#{club_id} and uid=#{uid}")
	void addTea(int club_id,int uid, long tea);
	@Select("${sql}")
	List<ClubMember> executeSql(String sql);
	
	@Update("update club_member set tea=tea-#{tea},frozen=frozen+#{tea} where club_id=#{club_id} and uid=#{uid}")
	void reduceTeaToFrozen(int club_id,int uid,long tea);
	
	@Update("update club_member set tea=tea-#{tea},safety=safety+#{tea} where club_id=#{club_id} and uid=#{uid}")
	void reduceTeaToSafety(int club_id,int uid, long tea);
	
	@Update("update club_member set tea=tea+#{tea},safety=safety-#{tea} where club_id=#{club_id} and uid=#{uid}")
	void reduceSafetyToTea(int club_id,int uid, long tea);
	
	@Delete("delete from club_member where club_id=#{club_id} and uid=#{uid}")
	void delete(int club_id, int uid);
	
	@Update("update club_member set tea=0,safety=0,frozen=0 where club_id=#{club_id} and uid=#{uid}")
	void kickoutClear(int club_id, int uid);
	
	@Update("update club_member set frozen=frozen-#{tea},tea=tea+#{tea} where club_id=#{club_id} and uid=#{uid}")
	void reduceFrozenToTea(int club_id,int uid, long tea);

}
